﻿using System;
using System.Collections.Generic;
 
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class per_phone : MpageBase
{
    protected Model.CMember cmember = null;
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public string  newmobile = Convert.ToString(HttpContext.Current.Request.Form["newmobile"]);//电话号码
    protected void mdifyBtn_Click(object sender, EventArgs e)
    {
        if (loginUserInfo != null && loginUserInfo.Id > 0)
        {
            string checkCode = "";
            cmember = BLL.CMember.GetModel(loginUserInfo.Id);

            Model.MsgSendInfo msgInfo = BLL.MsgSendInfo.GetModelOrderByAddtime(2, newmobile.Trim().ToString());
            if (msgInfo == null)
            {
                alertmessageAndGoback("您的电话号码有误！");
                return;
            }
            else
            {
                int effMinutes = (DateTime.Now - msgInfo.addTime).Minutes;
                checkCode = msgInfo.code;
            }
            if (!R_mobCheck(newmobile))
            {
                alertmessageAndGoback("此手机号码已经注册！");
                return;
            }
            else
            {
                if (checkcode.Text.Trim() == checkCode.ToUpper())
                {
                    if (cmember.zhifuPassword.Equals(BLL.Security.MD5(zhifupass.Text.Trim())))
                    {
                        cmember.mob = newmobile;
                        System.Web.HttpContext.Current.Session[BLL.CMember.LoginUserSessionKey] = cmember;
                        if (BLL.CMember.Update(cmember) > 0)
                        {
                            alertmessageAndGoback("新电话号码修改成功！");
                        }
                    }
                    else
                    {
                        alertmessageAndGoback("支付密码错误！");
                    }
                }
                else
                {
                    alertmessageAndGoback("短信验证码错误！");
                }
            }
        }
    }
    public bool R_mobCheck(string mob)
    {
        if (string.IsNullOrEmpty(mob))
        {
            return false;
        }
        mob = mob.Trim();
        if (mob.Length != 11)
        {
            return false;
        }
        if ("11".Equals(mob.Substring(0, 2)))
        {
            return false;
        }
        if (BLL.CMember.GetIsExitmob(mob))
        {
            return false;
        }
        return true;
    }
}